package net.loyintean.pearlshell.validation.rule;

import net.loyintean.pearlshell.validation.IValidRule;
import net.loyintean.pearlshell.validation.IValidRuleConfig;
import net.loyintean.pearlshell.validation.exception.ForceInteruptException;

class ObjNotNullValidRuleImpl implements IValidRule {

	ObjNotNullValidRuleImpl() {
		super();
	}

	/**
	 * @see net.loyintean.pearlshell.validation.IValidRule#valid(java.lang.Object,
	 *      net.loyintean.pearlshell.validation.IValidRuleConfig)
	 * @throws ForceInteruptException
	 *             toValid为空时，抛出异常，强制中断校验流
	 */
	@Override
	public boolean valid(Object toValid, IValidRuleConfig config)
			throws ForceInteruptException {
		if (toValid == null) {
			throw new ForceInteruptException(this.errorMsg(config));
		} else {
			return true;
		}
	}

	@Override
	public String errorMsg(IValidRuleConfig config) {
		return "不能为空";
	}

}
